package com.cskaoyan.controller;

import com.cskaoyan.bo.ConfigExpressBo;
import com.cskaoyan.bo.ConfigMallBo;
import com.cskaoyan.bo.ConfigOrderBo;
import com.cskaoyan.bo.ConfigWXBo;
import com.cskaoyan.service.ConfigService;


import com.cskaoyan.vo.BaseRespVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @auther hhy
 */
@RestController
@RequestMapping("admin/config")
public class ConfigController {
    @Autowired
    ConfigService configService;

    /**
     * 处理显示配置管理Get请求
     * 以url最后一个作为获取数据的参数，进行查询
     * 最后是mall的就查询mall相关的，express就是查询express相关的
     * @param condition
     * @return
     */
    @GetMapping("{condition}")
    public BaseRespVo configMall(@PathVariable String condition){
        Map configMall =  configService.selectMallConfig(condition);
        return BaseRespVo.ok(configMall);
    }
    /***********************************************************************/
    /**
     * 处理修改后的post请求
     */

    /**
     * 更新 商城配置
     * @param configMallBO
     * @return
     */
    @RequestMapping(value = "mall",method = RequestMethod.POST)
    public BaseRespVo configMall(@RequestBody ConfigMallBo configMallBO) {
        configService.updateConfigMall(configMallBO);
        return BaseRespVo.ok();
    }

    /**
     * 更新 运费配置
     * @param configExpressBo
     * @return
     */
    @RequestMapping(value = "express",method = RequestMethod.POST)
    public BaseRespVo configExpress(@RequestBody ConfigExpressBo configExpressBo) {
        configService.updateConfigExpress(configExpressBo);
        return BaseRespVo.ok();
    }

    /**
     * 更新 订单配置
     * @param configOrderBo
     * @return
     */
    @RequestMapping(value = "order",method = RequestMethod.POST)
    public BaseRespVo configOrder(@RequestBody ConfigOrderBo configOrderBo){
        configService.updateConfigOrder(configOrderBo);
        return BaseRespVo.ok();
    }

    /**
     * 更新 小程序配置
     * @param configWXBo
     * @return
     */
    @RequestMapping(value = "wx",method = RequestMethod.POST)
    public BaseRespVo configWX(@RequestBody ConfigWXBo configWXBo){
        configService.updateConfigWX(configWXBo);
        return BaseRespVo.ok();
    }

}
